package com.shopping_back.common;

import lombok.Data;

import java.util.Map;

@Data
public class Result {
    private static String SUCCESS_CODE = "200";
    private static String ERROR_CODE = "-1";

    private String code;
    private Object data;
    private String message;

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setData(data);
        return result;
    }

    public static Result success(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        return result;
    }

    public static Result success(String message){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMessage(message);
        return result;
    }

    public static Result success(Object data, String message){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setData(data);
        result.setMessage(message);
        return result;
    }

    public static Result error(String message){
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMessage(message);
        return result;
    }

    public static Result error(String code, String message){
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result success(String message, Map<String, Object> resultMap) {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMessage(message); // 设置成功消息（如"登录成功"）
        result.setData(resultMap);  // 添加这行，将用户数据设置到data字段
        return result;
    }
}